﻿// Copyright (C) 2009 Monadsphere <monadshpere@gmail.com>
//
// This file is part of Monadsphere.
//
// Monadsphere is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// Monadsphere is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Monadsphere. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;

using monadsphere.js;

/// <summary>
/// This namespace contains browser specific classes.
/// </summary>
/// 

namespace monadsphere.browser {

    /// <summary>
    /// This class is for window object.
    /// This is a static class.
    /// </summary>
    public class HtmlWindow {

        protected static JSVar window = JSVar.getExistingVariable<JSVar>("window");

        protected HtmlWindow() {
        }

        public static Navigator navigator {
            get {
                return window.getProperty<Navigator>("navigator");
            }
        }

        public static void alert(params JSVar[] values) {
            StringBuilder builder = new StringBuilder();
            int i = 0;
            foreach (JSVar v in values) {
                builder.Append(v.ToString());
                if (i++ < values.Length - 1) {
                    builder.Append("+");
                }
            }
            window.callProcedure("alert", builder.ToString());
        }

        public static T getVariable<T>(string name) where T: JSVar {
            return window.getProperty<T>(name);
        }

        public static void setVariable(string name, JSVar v) {
            window.setProperty(name, v);
        }

        public static JSFunction onunload {
            set {
                window.setProperty("onunload", value);
            }
        }
    }

    /// <summary>
    /// This is for window.navigator.
    /// </summary>
    public class Navigator: JSVar {
        public Navigator(JSVar stub)
            : base(stub) {
        }

        public JSString appCodeName {
            get {
                return getProperty<JSString>("appCodeName");
            }
        }

        public JSString appName {
            get {
                return getProperty<JSString>("appName");
            }
        }

        public JSString appMinorVersion {
            get {
                return getProperty<JSString>("appMinorVersion");
            }
        }

        public JSString appVersion {
            get {
                return getProperty<JSString>("appVersion");
            }
        }

        public JSString userAgent {
            get {
                return getProperty<JSString>("userAgent");
            }
        }
    }
}
